/*
 * Copyright (c) 2007 The Trustees of Indiana University. All rights reserved.
 * IU CSCI B534 Distributed Systems 2007-02-01 http://www.cs.indiana.edu/classes/b534
 */

package edu.indiana.cs.b534.torrent.struct;

import edu.indiana.cs.b534.torrent.InfoDictionary;
import edu.indiana.cs.b534.torrent.TDictionary;
import edu.indiana.cs.b534.torrent.TString;
import edu.indiana.cs.b534.torrent.TStruct;
import edu.indiana.cs.b534.torrent.TorrentMetainfo;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

public class TorrentMetainfoImpl extends TDictionaryImpl implements TorrentMetainfo {
	public final static TString ANNOUNCE_KEY = TStringImpl.newInstance("announce");
	public final static TString INFO_KEY = TStringImpl.newInstance("info");
	
	

    protected TString announce;
    protected InfoDictionary info;

    public static TorrentMetainfo deserialize(InputStream inStream) throws IOException {

        return newInstanceFrom(TDictionaryImpl.deserialize(inStream));
    }

    public static TorrentMetainfo newInstance() {
        return new TorrentMetainfoImpl();
    }

    public static TorrentMetainfo newInstanceFrom(TDictionary dictionary_) {
        Map<TString, ? extends TStruct> map = dictionary_.getDictionary();
        TorrentMetainfoImpl instance = new TorrentMetainfoImpl();
        instance.setDictionary(map);
        TStruct value = map.get(ANNOUNCE_KEY);
        instance.setAnnounce((TString)value);

        value = map.get(INFO_KEY);
        instance.setInfo(InfoDictionaryImpl.newInstanceFrom((TDictionary)value));
        return instance;
    }

    protected TorrentMetainfoImpl() {}

    public TString getAnnounce() {
    	return announce;
    }

    public void setAnnounce(TString announce_) {
    	this.announce = announce_;
    }

    public InfoDictionary getInfo() {
    	return info;
    }

    public void setInfo(InfoDictionary info) {
    	this.info = info;
    }

}
